<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>修改密码--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/resources/css/index.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-row">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">

		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="hidden" name="id" id="id" th:value="${session.user.id}">
				<input type="text" th:value="${session.user.name}" disabled class="layui-input layui-disabled">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password"  name="pwd" value="" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" name="newPwd" value="" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" name="confirmpwd" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="button" class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="/resources/layui/layui.js"></script>

<script type="text/javascript">

	var tableIns;
	layui.extend({
		dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
	}).use(['jquery','form','table','layer','dtree'],function() {
		var $ = layui.jquery;
		var form = layui.form;
		var table = layui.table;
		var layer = layui.layer;
		var dtree = layui.dtree;


		//添加验证规则
		form.verify({

			newPwd : function(value, item){
				if(value.length < 6){
					return "密码长度不能小于6位";
				}
			},
			confirmPwd : function(value, item){
				if(!new RegExp($("#oldPwd").val()).test(value)){
					return "两次输入密码不一致，请重新输入！";
				}
			}
		})



		form.on("submit(changePwd)", function (data) {

			//   console.log(data.field);
			$.post("/user/changeUserPwd", data.field, function (res) {
				if (res.code == 200) {
					layer.msg(res.msg);
					window.parent.location.href = "/sys/toLogin";
				}
				else {
					layer.msg(res.msg);
				}
			})

		})
	})

</script>
</body>
</html>